unit ufrLDFieldsConfig;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls, uLDStoreEditor, DB, Buttons;

type
  TfrLDFieldsConfig = class(TForm)
    btnOk: TButton;
    pnlButon: TPanel;
    pnlClient: TPanel;
    pgcConfig: TPageControl;
    btnCancel: TButton;
    tsBase: TTabSheet;
    tsDrop: TTabSheet;
    lblComponentDrop: TLabel;
    cbbComponentDrop: TComboBox;
    tsGetLabelField: TTabSheet;
    lstDataBase: TListBox;
    pnlLeftSQL: TPanel;
    pnlSQLClient: TPanel;
    mmoSQL: TMemo;
    lblPath: TLabel;
    edtPath: TEdit;
    btnDialogPath: TSpeedButton;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure lstDataBaseClick(Sender: TObject);
  private
    procedure LoadXML;
  published
  end;

var
  frLDFieldsConfig: TfrLDFieldsConfig;

implementation

uses
  ufrLDDrpCntrl, uLDXMLIntr;

{$R *.dfm}

procedure TfrLDFieldsConfig.FormShow(Sender: TObject);
var i:Integer;
begin
  LoadXML;
  edtPath.Text := StoreEditor.Path;
  for i := 0 to pred(length(LDComponentDragList)) do
    cbbComponentDrop.Items.Add(LDComponentDragList[i].Name);
  cbbComponentDrop.ItemIndex := cbbComponentDrop.Items.IndexOf(StoreEditor.ComponentDragCreate);
  if cbbComponentDrop.ItemIndex = -1 then
    cbbComponentDrop.ItemIndex := 0;
  lstDataBase.ItemIndex :=
    lstDataBase.Items.IndexOf(StoreEditor.DBServer)
end;

procedure TfrLDFieldsConfig.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  if ModalResult = mrOk then
  begin
    StoreEditor.Path := edtPath.Text;
    StoreEditor.ComponentDragCreate := cbbComponentDrop.Items[cbbComponentDrop.ItemIndex];
    if lstDataBase.ItemIndex >= 0 then
    StoreEditor.DBServer := lstDataBase.Items[lstDataBase.ItemIndex];
    StoreEditor.Save;
    ChangeTemplate;
  end;
end;

procedure TfrLDFieldsConfig.LoadXML;
var i:integer;
begin
  lstDataBase.Clear;
  mmoSQL.Clear;
  if Template <> nil then 
    for i:=0 to Template.Sqls.Count-1 do
    begin
      lstDataBase.Items.AddObject(Template.Sqls.Sql[i].Name, TObject(i) );
    end;
end;

procedure TfrLDFieldsConfig.lstDataBaseClick(Sender: TObject);
begin
  if lstDataBase.ItemIndex>=0 then
    if lstDataBase.ItemIndex <= Template.Sqls.Count-1 then
      mmoSQL.Text := Template.Sqls.Sql[lstDataBase.ItemIndex].Displaylabel.Query;
end;

end.
